package net.towee.client.gadgets.recentdocs;

import java.util.Arrays;
import java.util.List;

import net.towee.client.gadgets.GadgetInfo;
import net.towee.client.gadgets.GadgetPresenter;
import net.towee.client.i18n.ToweeConstants;
import net.towee.model.account.Board;
import net.towee.model.account.Gadget;
import net.towee.model.repo.DocumentType;

import com.google.gwt.inject.client.AsyncProvider;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Image;
import com.google.inject.Inject;

public class RecentDocumentsGadgetInfo implements GadgetInfo {
	public final static String CANONICAL_NAME = "recentDocs";
	
	// Injected
	@Inject ToweeConstants constants;
	@Inject AsyncProvider<RecentDocumentsGadget> asyncProvider;

	@Override
	public String getName() {
		return constants.gadgetRecentDocument();
	}

	@Override
	public String getCanonicalName() {
		return CANONICAL_NAME;
	}

	@Override
	public String getDescription() {
		return constants.gadgetRecentDocumentDescription();
	}
	
	@Override
	public List<DocumentType> getTypes() {
		return Arrays.asList( DocumentType.SIMPLE_DOC );
	}

	@Override
	public List<Image> getSceenshots() {
		return Arrays.asList();
	}

	@Override
	public void getGadgetContainer(final Gadget g, final Board b, final AsyncCallback<GadgetPresenter> callback) {
		asyncProvider.get(new AsyncCallback<RecentDocumentsGadget>(){
			@Override
			public void onFailure(Throwable caught) {
				callback.onFailure(caught);
			}

			@Override
			public void onSuccess(RecentDocumentsGadget result) {
				result.setGadgetAndBoard(g, b);
				callback.onSuccess( result );
			}
		});
	}

}
